﻿using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
using cludg.Domain.Content.Stories;

namespace cludg.Web.RenderHelpers
{
	public static class StoryLinkHelper
	{
		public static string StoryUrl(this HtmlHelper html, string id)
		{
			return UrlHelper.GenerateUrl(
					null,
					"Show",
					"Story",
					null,
					html.ViewContext.RequestContext.HttpContext.Request.Url.Host,
					null,
					new RouteValueDictionary(new { Id = id }),
					html.RouteCollection,
					html.ViewContext.RequestContext,
					true);
		}

		public static string StoryUrl(this HtmlHelper html, Story story)
		{
			return UrlHelper.GenerateUrl(
				"Story", 
				null, 
				null, 
				null, 
				html.ViewContext.RequestContext.HttpContext.Request.Url.Host,
				null,
				new RouteValueDictionary(new { name = story.UniqueName}),
				html.RouteCollection,
				html.ViewContext.RequestContext,
				true);
		}

		public static MvcHtmlString StoryLink(this HtmlHelper html, string linkText, Story story, object htmlAttributes = null)
		{
			return html.RouteLink(linkText, "Story", new { name = story.UniqueName }, htmlAttributes);
		}

		public static MvcHtmlString StoryLink(this HtmlHelper html, string linkText, string storyId, object htmlAttributes = null)
		{
			return html.ActionLink(linkText, "Show", "Story", new { id = storyId }, htmlAttributes);
		}
	}
}